<?php

class Afmelding
{
  public $les_ID;
  public $user_ID;

  function __construct($les_id, $user_id)
  {
    $this->les_ID  = $les_id;
    $this->user_ID = $user_id;
  }    
  
  public static function by_week($week, $year)
  {
    $query = mysql_query('SELECT DISTINCT '.DB_LES.'.dag, '.DB_LES.'.tijd, leden.voornaam, leden.achternaam, leden.email, '.DB_AFMELDING.'.afmeld_dag, '.DB_AFMELDING.'.week, '.DB_AFMELDING.'.afmeld_tijd FROM '.DB_LES.' INNER JOIN '.DB_AFMELDING.' INNER JOIN leden ON ('.DB_AFMELDING.'.les_ID='.DB_LES.'.ID AND '.DB_AFMELDING.'.user_ID=leden.ID) WHERE '.DB_LES.'.week="'.$week.'" AND '.DB_LES.'.jaar="'.$year.'" ORDER BY '.DB_LES.'.dag');
    
    while ($row = mysql_fetch_assoc($query))
      $afmeldingen[] = $row;

    return $afmeldingen;
  }

  public static function count_afmeldingen($week, $year)
  {
    $query  = mysql_query('SELECT COUNT(DISTINCT '.DB_AFMELDING.'.user_ID) FROM '.DB_LES.' INNER JOIN '.DB_AFMELDING.' ON ('.DB_AFMELDING.'.les_ID = '.DB_LES.'.ID) WHERE '.DB_LES.'.week="'.$week.'" AND '.DB_LES.'.jaar="'.$year.'"');
    $row    = mysql_fetch_assoc($query);
    $aantal = $row['COUNT(DISTINCT '.DB_AFMELDING.'.user_ID)'];

    $message = "afmeldingen  " . Website::create_link("afmeldingen","tonen");

    switch ($aantal)
    {
      case 0  : return "Er zijn deze week <span class='nr'>(geen)</span> afmeldingen.";
      case 1  : return "Er is deze week <span class='nr'>(1)</span> $message";
      default : return "Er zijn deze week <span class='nr'>($aantal)</span> $message";
    }
  }
}

?>
